﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IloveRSS.Models;
using System.Configuration;
using IloveRSS.Core;

namespace IloveRSS.Controllers
{
    public class SettingsController : Controller
    {
        //
        // GET: /Settings/
        private DataManager dataManager;

        public SettingsController(DataManager dm)
        {
            dataManager = dm;
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Index()
        {
            List<ThemeElement> themes = new List<ThemeElement>();
            ThemeSection section =
                (ThemeSection)ConfigurationManager.GetSection("themeSection");
            foreach (ThemeElement element in section.Elements)
            {
                if (element.Name != null && element.Name != "")
                {
                    themes.Add(element);
                }
            }
            ViewBag.Themes = new SelectList(themes, "file", "name");
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(string themes)
        {
            Response.Cookies.Add(new HttpCookie(HttpContext.User.Identity.Name, themes));
            Response.Cookies[HttpContext.User.Identity.Name].Expires = DateTime.MaxValue;
            return RedirectToAction("Index");
        }
    }
}
